$(document).ready(function () {
    $("#resPopup").css("overflow","scroll")
    //获取当前页的头部标题
    const nowHeadTitle=$(".headTitle").html();
    //显示预约弹窗
    $(".fixedBottomBtnContent").click(function (e) {
        ///阻止事件冒泡，避免点击子元素时触发父元素的点击事件
        e.stopPropagation();
        e.preventDefault()
        //获取预约弹窗的zIndex的值
        let resPopup_zIndex=$("#resPopup").css("z-index");
        //获取菜单栏的zIndex的值
        let popup_zIndex=$("#popupTop").css("z-index");
        // 如果菜单栏弹窗的zIndex大于预约弹窗则提高预约弹窗的zIndex的值
        if(popup_zIndex>=resPopup_zIndex){
            $("#resPopup").css("z-index",popup_zIndex+1);
        }
        $(document.body).css("overflow-y","hidden")
        document.documentElement.style.overflowY='hidden';
        $('#resPopup').removeClass('hideResPopup');
        $(".headTitle").html('预约');
    })
    //隐藏预约弹窗
    $("#resPopup").click(function () {
        $(document.body).css("overflow-y","auto");
        document.documentElement.style.overflowY='auto';
        $(".headTitle").html(nowHeadTitle);
        $('#resPopup').addClass('hideResPopup');
    });
    ////阻止事件冒泡，避免点击子元素填写数据时自动隐藏了预约弹窗
      $("#resForm").click(function (e) {
        e.stopPropagation();
    })
    // 弹出选择医生弹窗
    $("#resDoctors").focus(function (e) {
        //阻止事件冒泡，避免点击子元素，父元素的点击事件也被触发
        e.stopPropagation();
        //禁止手机端弹出虚拟键盘
        $("#resDoctors").blur();
        // 将滚动条滚动到最上方，同时阻止选择医生时的滑动事件
        $("#resPopup").scrollTop(0);
        $("#resPopup").css("overflow","hidden")
        //显示弹窗，10毫秒后将弹窗平移上来 以下同理
        $('#modalDoctors').css("display","block")
        setTimeout(function () {
            $('#modalDoctors').css({"-webkit-transform":"translate3d(0,0,0)","transform":"translate3d(0,0,0)"});
        },10);
        //显示遮罩
        $("#resMask").css("display","block");
        $("#resMask1").css("display","block");

    })
    //点击遮罩隐藏模态
    $("#resMask").click(function (e) {
        e.stopPropagation();
        $("#resPopup").css("overflow","scroll")
        $("#resMask").css("display","none");
        $("#resMask1").css("display","none");
        $('#modalDoctors').css({"-webkit-transform":"translate3d(0,150%,0)","transform":"translate3d(0,150%,0)"});
        $('#modalDate').css({"-webkit-transform":"translate3d(0,150%,0)","transform":"translate3d(0,150%,0)"});
        setTimeout(function () {
            $('#modalDoctors').css("display","none");
            $('#modalDate').css("display","none");
        },200);
    })
    //点击遮罩隐藏模态
    $("#resMask1").click(function (e) {
        e.stopPropagation();
        $("#resPopup").css("overflow","scroll")
        $("#resMask").css("display","none");
        $("#resMask1").css("display","none");
        $('#modalDoctors').css({"-webkit-transform":"translate3d(0,150%,0)","transform":"translate3d(0,150%,0)"});
        $('#modalDate').css({"-webkit-transform":"translate3d(0,150%,0)","transform":"translate3d(0,150%,0)"});
        setTimeout(function () {
            $('#modalDoctors').css("display","none");
            $('#modalDate').css("display","none");
        },200);
    })
    //点击单选框触发事件，隐藏模态
    $(":radio").click(function () {
        $("#resPopup").css("overflow","scroll")
        $("#resMask").css("display","none");
        $("#resMask1").css("display","none");
        $('#modalDoctors').css({"-webkit-transform":"translate3d(0,150%,0)","transform":"translate3d(0,150%,0)"});
        setTimeout(function () {
            $('#modalDoctors').css("display","none");
        },200);
        $("#resDoctors").val($('input:radio[name="theDoctors"]:checked').val())
        //document.body.style.overflow="auto";
    })
    //点击日期控件显示日期
    $("#resDate").click(function (e) {
        e.stopPropagation();

        $("#resPopup").scrollTop(0);
        $("#resPopup").css("overflow","hidden")
        $('#modalDate').css("display","block")
        setTimeout(function () {
            $('#modalDate').css({"-webkit-transform":"translate3d(0,0,0)","transform":"translate3d(0,0,0)"});
        },10);
        $("#resMask").css("display","block");
        $("#resMask1").css("display","block");
    })
    //点击预约将数据返回到select中，并关闭模态
    $(".noFill").click(function () {
        $("#resPopup").css("overflow","scroll")
       $("#resDateOption").val($(this).val());
       // 将值传给下拉列表
       document.getElementById("resDateOption").innerHTML=$(this).val()
        $("#resMask").css("display","none");
        $("#resMask1").css("display","none");
        $('#modalDate').css({"-webkit-transform":"translate3d(0,150%,0)","transform":"translate3d(0,150%,0)"});
        setTimeout(function () {
            $('#modalDate').css("display","none")
        },200);
    })
    $("#modalDoctors").click(function (e) {
        e.stopPropagation();
    })
    $("#modalDate").click(function (e) {
        e.stopPropagation();
    })
})
